package com.wuye.zlgl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.zlgl.domain.WyRoomRent;
import com.wuye.zlgl.service.IWyRoomRentService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 房屋租赁Controller
 * 
 * @author avalon
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/zlgl/roomRent")
public class WyRoomRentController extends BaseController
{
    @Autowired
    private IWyRoomRentService wyRoomRentService;
    /**
     * 根据房屋id和单元id查询房屋信息
     */
    @GetMapping("/getRoomRent/{unitId}/{roomId}")
    public AjaxResult getRoomRent(@PathVariable("unitId") Long unitId,@PathVariable("roomId") Long roomId)
    {
        return success(wyRoomRentService.getInfoById(unitId,roomId));
    }

    /**
     * 查询房屋租赁列表
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyRoomRent wyRoomRent)
    {
        startPage();
        List<WyRoomRent> list = wyRoomRentService.selectWyRoomRentList(wyRoomRent);
        return getDataTable(list);
    }

    /**
     * 导出房屋租赁列表
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:export')")
    @Log(title = "房屋租赁", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyRoomRent wyRoomRent)
    {
        List<WyRoomRent> list = wyRoomRentService.selectWyRoomRentList(wyRoomRent);
        ExcelUtil<WyRoomRent> util = new ExcelUtil<WyRoomRent>(WyRoomRent.class);
        util.exportExcel(response, list, "房屋租赁数据");
    }

    /**
     * 获取房屋租赁详细信息
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyRoomRentService.selectWyRoomRentById(id));
    }

    /**
     * 新增房屋租赁
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:add')")
    @Log(title = "房屋租赁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyRoomRent wyRoomRent)
    {
        return toAjax(wyRoomRentService.insertWyRoomRent(wyRoomRent));
    }

    /**
     * 修改房屋租赁
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:edit')")
    @Log(title = "房屋租赁", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyRoomRent wyRoomRent)
    {
        return toAjax(wyRoomRentService.updateWyRoomRent(wyRoomRent));
    }

    /**
     * 删除房屋租赁
     */
    @PreAuthorize("@ss.hasPermi('zlgl:roomRent:remove')")
    @Log(title = "房屋租赁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyRoomRentService.deleteWyRoomRentByIds(ids));
    }
}
